#include "mainview.h"
#include "ui_mainview.h"

MainView::MainView(QWidget *parent) :
    BaseView(parent),
    ui(new Ui::MainView)
{
    ui->setupUi(this);
    init();
}

void MainView::init()
{
    m_curTimer = new QTimer(this);
    m_curTimer->setInterval(1000);
    m_curTimer->start();
    onCurTimeout(); // 初始化时间
    connect(m_curTimer,&QTimer::timeout,this,&MainView::onCurTimeout);
    ui->currentViewLab->setText("主界面");
    // 添加工具栏界面
    m_toolBtn = new ToolWidget(this);
    ui->toolLayout->addWidget(m_toolBtn);

}

//void MainView::showView()
//{
//    this->show();
//}

//void MainView::hideView()
//{
//    this->hide();
//}

#include <QDebug>

void MainView::update(QSharedPointer<Data> dataPtr)
{
    QSharedPointer<MainData> mainDataPtr = dataPtr.dynamicCast<MainData>();
    qDebug() << mainDataPtr->getToolName();
}

MainView::~MainView()
{
    delete ui;
}

void MainView::onCurTimeout()
{
    QDateTime currentTime = QDateTime::currentDateTime();
    QString formatTime = currentTime.toString("yyyy-MM-dd HH:mm:ss");
    ui->timeLabel->setText(formatTime);
}
